<?php


use yii\bootstrap\BootstrapAsset;
use yii\helpers\Url;
use common\models\business\BusinessInspection;
use common\models\business\BusinessFarmers;
BootstrapAsset::register($this);

$sql = 'select ins.id,ins.business_person,business_personid,ins.createtime,ins.status,ins.address from '.BusinessInspection::tableName().' as ins where ins.pigid=:pigid';
$insp = Yii::$app->db->createCommand($sql)->bindValues([':pigid'=>$model->id])->queryAll();

$farmer = Yii::$app->db->createCommand('select name,id from '.BusinessFarmers::tableName().' where id=:livery')->bindValues([':livery'=>$model->livery])->queryOne();

?>




<div class="row">
    <div class="col-md-12">
        <h3>巡检记录</h3>
        <table class="table table-hover">
            <tr>
                <th>巡检仔猪</th>
                <th>巡检人</a></th>
                <th>农户</th>
                <th>巡检时间</th>
                <th>巡检地址</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            <?php foreach ($insp as $key => $row) {?>
                <tr>
                    <td><?= $model->no ?></td>
                    <td><a target="_blank" href="<?= Url::to(['/business/person/view','id'=>$row['business_personid']])?>"> <?= $row['business_person'] ?></a></td>
                    <td><a target="_blank" href="<?= Url::to(['/business/farmers/view','id'=>$farmer['id']])?>"> <?= $farmer['name'] ?></a></td>
                    <td><?= date('Y-m-d',$row['createtime']) ?></td>
                    <td><?= $row['address'] ?></td>
                    <td>
                        <?php if($row['status'] == BusinessInspection::STATUS_PASSED) { ?>
                            <?= \yii\helpers\Html::button(BusinessInspection::$statues[$row['status']],['class'=>'btn btn-success btn-xs']) ?>
                        <?php } else if($row['status'] == BusinessInspection::STATUS_UNPASSED) { ?>
                            <?= \yii\helpers\Html::button(BusinessInspection::$statues[$row['status']],['class'=>'btn btn-danger btn-xs']) ?>
                        <?php } else { ?>
                            <?= \yii\helpers\Html::button(BusinessInspection::$statues[$row['status']],['class'=>'btn btn-default btn-xs']) ?>
                        <?php } ?>
                    </td>
                    <td><a target="_blank" href="<?= Url::to(['/business/new-business-inspection/view','id'=>$row['id']])?>">查看</a> | <a target="_blank" href="<?= Url::to(['/business/new-business-inspection/update','id'=>$row['id']])?>">修改</a></td>
                </tr>
            <?php } ?>
        </table>
    </div>
</div>